<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------
namespace app\user_center\behavior\user\bind_mobile_before;

/**
 * 检测手机号码绑定
 * @package app\user_center\behavior\user\bind_mobile_before
 * @author shiqiang
 */
class checkMobileBind{
    /**
     * 执行行为 run方法是Behavior唯一的接口
     * @access public
     * @return void
     */
    public function run($params){
		$mobile 	= $params['mobile'];
        $bind_type 	= $params['bind_type']; // 1 微信 2 苹果id

        $map['mobile'] = $mobile;
        $mobile_info = model('UcMemberMobile', 'model\user') -> where($map) -> find();

        if(!empty($mobile_info)){
            $map = [];
            $map['uid'] = $mobile_info['uid'];
            if($bind_type == 1){
                $result = model('UcMemberWechat', 'model\user') -> where($map) -> find();
            }
            if($bind_type == 2){
                $result = model('UcMemberApple', 'model\user') -> where($map) -> find();
            }
            if(!empty($result)){
                return array_out(-1001,'手机号码已被使用');
            }
        }

//		$result = model('UcMemberMobile', 'model\user') -> getDataByUid($uid);
//		if($result['code'] > 0){
//			return array_out(-1001,'该用户已绑定手机');
//		}
//
//		$result = model('UcMemberMobile', 'model\user') -> getDataByMobile($mobile);
//		if($result['code'] > 0){
//			return array_out(-1001,'手机号码已被使用');
//		}
    }
}
